package com.gaoyi.crm.db;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.gaoyi.crm.db.dao.HttpCacheDao;
import com.gaoyi.crm.db.entity.HttpCache;
import com.gaoyi.crm.util.AppUtil;

@Database(entities = {HttpCache.class},version = 1,exportSchema = false)
public abstract class CacheDatabase extends RoomDatabase {
    private static final String DB_NAME = "MyCache.db";
    public static final String TABLE_HTTP_CACHE = "sys_httpCache";

    private volatile static CacheDatabase INSTANCE;
    public abstract HttpCacheDao getCacheDao();

    public static synchronized CacheDatabase getDatabase() {
        if (INSTANCE == null) {
            synchronized (CacheDatabase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(AppUtil.getContext(),
                                    CacheDatabase.class, DB_NAME)
                            .build();
                }
            }
        }
        return INSTANCE;
    }
}
